
DEFINE VARIABLE voutput AS CHARACTER  NO-UNDO
                initial "\\192.168.12.12\shared$\output\csv\".
DEFINE STREAM Bfftp.
define variable vdb like ad_name_control initial "".
DEFINE VARIABLE VFTP as logical initial no.

for first ad_mstr no-lock where ad_addr = "~~reports".
end.
if avail ad_mstr then do:
    assign vdb =  ad_name_control .
end.

find code_mstr NO-LOCK WHERE code_fldname = "exptab2csv"
                         and code_value   = "output" no-error.
if avail code_mstr then do:
    assign voutput = code_cmmt.
end.
find code_mstr NO-LOCK WHERE code_fldname = "exptab2csv"
                         and code_value   = "ftpornot" no-error.
if avail code_mstr and code_cmmt = "yes" then do:
    assign vftp = yes.
end.

{hkptmstr.i voutput vdb}
{hkrodet.i voutput vdb}
{hkcodemstr.i voutput vdb}
{hkempmstr.i voutput vdb}

if vftp then do:
/*     voutput = "Rar.exe a  -ep -tk -df .\" + vdb + "erp"               */
/*             + string(year(today),"9999") + string(month(today),"99")  */
/*             + string(day(today),"99") + ".rar " + voutput + "*.csv".  */
/*     dos silent  value(voutput).                                       */

    output stream bfftp to ".\ftprep.bat".
        put stream bfftp "cd /d c:\qadguicli" skip.
        put stream bfftp "ftp -i -s:c:\qadguicli\ftppara.txt" skip.
        put stream bfftp "exit".
    output stream bfftp close.

    output stream bfftp to ".\ftppara.txt".
        FOR FIRST code_mstr no-lock where code_fldname = "ftppara"
                                      and code_value   = "ipaddress":
        end.
        if avail code_mstr then do:
            put stream bfftp "open " code_cmmt format "x("
                     + string(length(code_cmmt)) + ")" skip.
        end.
        FOR FIRST code_mstr no-lock where code_fldname = "ftppara"
                                      and code_value   = "user":
        end.
        if avail code_mstr then do:
            put stream bfftp code_cmmt format "x("
                     + string(length(code_cmmt)) + ")" skip.
        end.
        FOR FIRST code_mstr no-lock where code_fldname = "ftppara"
                                      and code_value   = "password":
        end.
        if avail code_mstr then do:
            put stream bfftp code_cmmt format "x("
                     + string(length(code_cmmt)) + ")" skip.
        end.
        put stream bfftp "lcd c:\qadguicli" skip.
        FOR FIRST code_mstr no-lock where code_fldname = "ftppara"
                                      and code_value   = "dir":
        end.
        if avail code_mstr then do:
            put STREAM bfftp UNFORMAT  "cd " code_cmmt skip.
        end.
        put stream bfftp UNFORMAT "mput " + voutput + vdb + "*.csv " format "x(120)" skip.
        put stream bfftp "bye" skip.
    output stream bfftp close.
     dos silent  c:\qadguicli\ftprep.bat.
/*      dos silent value("del c:\qadguicli\" + vdb + "erp" */
/*                       + string(year(today),"9999")      */
/*                       + string(month(today),"99")       */
/*                       + string(day(today),"99")         */
/*                       + ".rar ").                       */
     dos silent  "del c:\qadguicli\ftprep.bat /s/q/f/a".
     dos silent  "del c:\qadguicli\ftppara.txt /s/q/f/a".
end.
QUIT.
